<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.id ? '详情' : '详情'"
    :close-on-click-modal="true"
    :visible.sync="visible2"
    :modal="false"
    width="60%">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="130px">
      <span v-if="dataForm.type === '线上订单'">
      <strong>商家信息：</strong>
      <el-row :gutter="20">
        <el-col :span="6">
          <span>商家账号：{{dataForm.storeUserName}}</span>
        </el-col>
        <el-col :span="6">
          <span>商家名称：{{dataForm.storeTrueName}}</span>
        </el-col>
        <el-col :span="6">
          <span>商家类型：{{dataForm.storeUserType === 1 ? '运营商' : (dataForm.storeUserType === 2 ? '普通联盟店' : (dataForm.storeUserType === 3 ? '消费者' : (dataForm.storeUserType === 4 ? 'VIP会员' : (dataForm.storeUserType === 5 ? '中级联盟店' : (
              dataForm.storeUserType === 6 ? '高级联盟店' : (dataForm.storeUserType === 7 ? '城市合伙人' : (dataForm.storeUserType === 8 ? '城市合伙人联盟店' : '')))))))}}</span>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <span>上级账号：{{dataForm.storeSuperiorUserName}}</span>
        </el-col>
        <el-col :span="6">
          <span>上级名称：{{dataForm.storeSuperiorTrueName}}</span>
        </el-col>
        <el-col :span="6">
          <span>负责人名：{{dataForm.storeSuperiorRealName}}</span>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <span>抽佣比例：{{dataForm.storeCommission}}%</span>
        </el-col>
      </el-row><br/>

      <strong>下单者信息：</strong>
      <el-row :gutter="20">
        <el-col :span="6">
          <span>消费者账号：{{dataForm.payUserName}}</span>
        </el-col>
        <el-col :span="6">
          <span>消费者名称：{{dataForm.payTrueName}}</span>
        </el-col>
        <el-col :span="6">
          <span>消费者类型：{{dataForm.payUserType === 1 ? '运营商' : (dataForm.payUserType === 2 ? '普通联盟店' : (dataForm.payUserType === 3 ? '消费者' : (dataForm.payUserType === 4 ? 'VIP会员' : (dataForm.payUserType === 5 ? '中级联盟店' : (
              dataForm.payUserType === 6 ? '高级联盟店' : (dataForm.payUserType === 7 ? '城市合伙人' : (dataForm.payUserType === 8 ? '城市合伙人联盟店' : '')))))))}}</span>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <span>上级账号：{{dataForm.paySuperiorUserName}}</span>
        </el-col>
        <el-col :span="6">
          <span>上级名称：{{dataForm.paySuperiorTrueName}}</span>
        </el-col>
      </el-row><br/>
<!--      <strong>商品明细：</strong>
      <el-row :gutter="20" v-for="(item, index) in dataForm.list" :key="index">
        <el-col :span="8">
          <span style="width:200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;">商品名：{{item.goodsName}}</span>
        </el-col>
        <el-col :span="4" v-if="dataForm.orderType === 0">
          <span>金额：￥{{item.goodsPrice}}</span>
        </el-col>
        <el-col :span="4" v-if="dataForm.orderType === 0">
          <span>赠积分：{{item.goodsCommission}}</span>
        </el-col>
        <el-col :span="4" v-if="dataForm.orderType === 1">
          <span>扣积分：{{item.goodsIntegralPrice}}</span>
        </el-col>
        <el-col :span="3">
          <span>数量：{{item.goodsCount}}</span>
        </el-col>
        <el-col :span="4">
          <span>类型：{{item.typeId === 0 ? '自营商品' : (item.typeId === 1 ? '抵扣券' : (item.typeId === 2 ? '体验券' : (item.typeId === 3 ? '券兑换商品' : (item.typeId === 4 ? '拉新商品' : (item.typeId === 5 ? '特价拼团' : '')))))}}</span>
        </el-col>
      </el-row>-->
      <strong>商品明细：</strong>
      <el-table
        :data="dataForm.list"
        border="1"
        v-loading="dataListLoading"
        @selection-change="selectionChangeHandle"
        style="width: 100%;">
      <el-table-column
        prop="goodsName"
        header-align="center"
        align="center"
        label="商品名">
      </el-table-column>
      <el-table-column
        prop="goodsPrice"
        header-align="center"
        align="center"
        label="金额">
        <template slot-scope="scope">
          <span v-if="dataForm.orderType === 0">￥{{scope.row.goodsPrice}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="goodsCommission"
        header-align="center"
        align="center"
        label="赠积分">
        <template slot-scope="scope">
          <span v-if="dataForm.orderType === 0">{{scope.row.goodsCommission}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="goodsIntegralPrice"
        header-align="center"
        align="center"
        label="扣积分">
        <template slot-scope="scope">
          <span v-if="dataForm.orderType === 1">{{scope.row.goodsIntegralPrice}}</span>
        </template>
      </el-table-column>
        <el-table-column
          prop="goodsCount"
          header-align="center"
          align="center"
          label="数量">
          <template slot-scope="scope">
            <span>{{scope.row.goodsCount}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="typeId"
          header-align="center"
          align="center"
          label="类型">
          <template slot-scope="scope">
            <span>{{scope.row.typeId === 0 ? '自营商品' : (scope.row.typeId === 1 ? '抵扣券' : (scope.row.typeId === 2 ? '体验券' : (scope.row.typeId === 3 ? '券兑换商品' : (scope.row.typeId === 4 ? '拉新商品' : (scope.row.typeId === 5 ? '特价拼团' : '')))))}}</span>
          </template>
         </el-table-column>
      </el-table><br/>
      <el-row>
        <el-col><span>配送费：{{dataForm.deliverMoney}}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5" v-if="dataForm.orderType === 0">
          <span>合计金额：￥{{dataForm.totalMoney}}</span>
        </el-col>
        <el-col :span="5">
          <span>商家实际到账金额：￥{{dataForm.arriveMoney}}</span>
        </el-col>
        <el-col :span="5">
          <span>商家实收积分：{{dataForm.coupons}}</span>
        </el-col>
        <el-col :span="5">
          <span>消费者获得积分：{{dataForm.couponMoney}}</span>
        </el-col>
        <el-col :span="5">
          <span>配送方式：{{dataForm.distributionType === 0 ? '物流' : (dataForm.distributionType === 1 ? '自取' : (dataForm.distributionType === 2 ? '商家配送' : (dataForm.distributionType === 3 ? '送贝配送' : '')))}}</span>
        </el-col>
        <el-col :span="5">
          <span>服务费：￥{{dataForm.serviceMoney}}</span>
        </el-col>
        <el-col :span="5">
          <span>平台收益：￥{{dataForm.platformMoney}}</span>
        </el-col>
      </el-row><br/>
      <strong>交易信息：</strong>
      <el-row :gutter="20">
        <el-col :span="5">
          <span>订单编号：{{dataForm.orderNo}}</span>
        </el-col>
        <el-col :span="5">
          <span>下单时间：{{dataForm.createTime}}</span>
        </el-col>
        <el-col :span="7">
          <span>支付时间：</span>
        </el-col>
        <el-col :span="7">
          <span>商家确认时间：{{dataForm.confirmTime}}</span>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">
          <span>完成时间：{{dataForm.successTime}}</span>
        </el-col>
        <el-col :span="5">
          <span>支付方式：{{dataForm.payFrom === 0 ? '微信' : (dataForm.payFrom === 1 ? '支付宝' : '')}}</span>
        </el-col>
        <el-col :span="7">
          <span>支付编号：{{dataForm.orderUnique}}</span>
        </el-col>
        <el-col :span="7">
          <span>支付流水号：{{dataForm.tradeNo}}</span>
        </el-col>
      </el-row><br/>

      <strong>其他：</strong>
      <el-row :gutter="20">
        <el-col :span="5">
          <span>订单来源：{{dataForm.orderSrc === 0 ? '安卓' : (dataForm.orderSrc === 1 ? '苹果' : (dataForm.orderSrc === 2 ? '小程序' : ''))}}</span>
        </el-col>
        <el-col :span="5">
          <span>配送方式：{{dataForm.distributionType === 0 ? '物流' : (dataForm.distributionType === 1 ? '自取' : (dataForm.distributionType === 2 ? '商家配送' : (dataForm.distributionType === 3 ? '送贝配送' : '')))}}</span>
        </el-col>
        <el-col :span="5">
          <span>支付方式：{{dataForm.orderType === 0 ? '现金订单' : (dataForm.orderType === 1 ? '积分订单' : '')}}</span>
        </el-col>
        <el-col :span="5">
          <span>订单地址：{{dataForm.addressText}}</span>
        </el-col>
      </el-row>
      </span>

      <span v-if="dataForm.type === '买单' || dataForm.type === '扫码'">
      <el-row :gutter="20">
        <el-col :span="10">
            <span>订单号：{{dataForm.orderNo}}</span>
        </el-col>
        <el-col :span="10">
            <span>消费者账号：{{dataForm.payUserName}}</span>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="10">
            <span>消费者名称：{{dataForm.payTrueName}}</span>
        </el-col>
        <el-col :span="10">
            <span>消费者类型：{{dataForm.payUserType === 1 ? '运营商' : (dataForm.payUserType === 2 ? '普通联盟店' : (dataForm.payUserType === 3 ? '消费者' : (dataForm.payUserType === 4 ? 'VIP会员' :
              (dataForm.payUserType === 5 ? '中级版联盟店' : (dataForm.payUserType === 6 ? '高级版联盟店' : (dataForm.payUserType === 7 ? '城市合伙人' : (dataForm.payUserType === 8 ? '城市合伙人联盟店' : '')))))))}}</span>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="10">
            <span>商家账号：{{dataForm.storeUserName}}</span>
        </el-col>
        <el-col :span="10">
            <span>商家名称：{{dataForm.storeTrueName}}</span>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="10">
            <span>下单时间：{{dataForm.createTime}}</span>
        </el-col>
        <el-col :span="10">
            <span>订单总金额：￥{{dataForm.totalMoney}}</span>
        </el-col>
        <el-col :span="10">
            <span>支付方式：{{dataForm.payFrom === 0 ? '微信' : (dataForm.payFrom === 1 ? '支付宝' : '')}}</span>
        </el-col>
        <el-col :span="10">
            <span>订单来源：{{dataForm.orderSrc === 0 ? '安卓' : (dataForm.payFrom === 1 ? '苹果' : '小程序')}}</span>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="10">
            <span>商家实到：￥{{dataForm.arriveMoney}}</span>
        </el-col>
        <el-col :span="10">
            <span>支付类型：￥{{dataForm.orderType === 1 ? '积分支付' : (dataForm.orderType === 2 ? '现金买单' : '')}}</span>
        </el-col>
        <el-col :span="10">
            <span v-show="dataForm.orderType !== 1">平台分佣：{{dataForm.storeCommission}}%</span>
        </el-col>
        <el-col :span="10">
            <span>服务费：￥{{dataForm.serviceMoney}}</span>
        </el-col>
        <el-col :span="10">
            <span v-show="dataForm.orderType !== 1">平台收益：￥{{dataForm.platformMoney}}</span>
        </el-col>
        <el-col :span="10">
            <span>支付积分：{{dataForm.payIntegral}}</span>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="10">
            <span>流水号：{{dataForm.tradeNo}}</span>
        </el-col>
        <el-col :span="10">
            <span>微信/支付宝ID：{{dataForm.orderUnique}}</span>
        </el-col>
      </el-row>
      </span>
    </el-form>
    <!-- <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span> -->
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible2: false,
        dialogImageUrl: '',
        dialogVisible: false,
        dataForm: {
          storeUserName: '',
          orderid: 0,
          storeTrueName: '',
          storeUserType: '',
          storeSuperiorUserName: '',
          storeSuperiorTrueName: '',
          storeSuperiorRealName: '',
          payUserName: '',
          payTrueName: '',
          payUserType: '',
          paySuperiorUserName: '',
          paySuperiorTrueName: '',
          orderNo: '',
          createTime: '',
          confirmTime: '',
          successTime: '',
          payFrom: '',
          orderSrc: '',
          orderUnique: '',
          tradeNo: '',
          addressText: '',
          distributionType: '',
          arriveMoney: '',
          coupons: '',
          totalMoney: '',
          couponMoney: '',
          orderType: '',
          storeCommission: '',
          deliverMoney: '',
          list: [],
          type: '',
          platformMoney: '',
          serviceMoney: ''
        },
        dataRule: {
          orderNo: []
        }
      }
    },
    methods: {
      // 图片预览
      handlePreview (file) {
        this.dialogImageUrl = file.url
        this.dialogVisible = true
      },
      init (no, type) {
        debugger
        this.dataForm.type = ''
        if (type === 1) {
          this.dataForm.type = '线上订单'
        } else {
          this.dataForm.type = '买单'
        }
        this.dataForm.orderid = 11110
        this.visible2 = true
        this.$nextTick(() => {
          // this.$refs['dataForm'].resetFields()
          if (this.dataForm.orderid) {
            debugger
            this.$http({
              url: this.$http.adornUrl(`/user/cashAudit/getOrderDetails/${no}/${type}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.storeUserName = data.data.storeUserName
                this.dataForm.storeTrueName = data.data.storeTrueName
                this.dataForm.storeUserType = data.data.storeUserType
                this.dataForm.storeSuperiorUserName = data.data.storeSuperiorUserName
                this.dataForm.storeSuperiorTrueName = data.data.storeSuperiorTrueName
                this.dataForm.storeSuperiorRealName = data.data.storeSuperiorRealName
                this.dataForm.payUserName = data.data.payUserName
                this.dataForm.payTrueName = data.data.payTrueName
                this.dataForm.payUserType = data.data.payUserType
                this.dataForm.paySuperiorUserName = data.data.paySuperiorUserName
                this.dataForm.paySuperiorTrueName = data.data.paySuperiorTrueName
                this.dataForm.orderNo = data.data.orderNo
                this.dataForm.createTime = data.data.createTime
                this.dataForm.confirmTime = data.data.confirmTime
                this.dataForm.successTime = data.data.successTime
                this.dataForm.payFrom = data.data.payFrom
                this.dataForm.orderSrc = data.data.orderSrc
                this.dataForm.orderUnique = data.data.orderUnique
                this.dataForm.tradeNo = data.data.tradeNo
                this.dataForm.addressText = data.data.addressText
                this.dataForm.distributionType = data.data.distributionType
                this.dataForm.arriveMoney = data.data.arriveMoney
                this.dataForm.coupons = data.data.coupons
                this.dataForm.totalMoney = data.data.totalMoney
                this.dataForm.couponMoney = data.data.couponMoney
                this.dataForm.orderType = data.data.orderType
                this.dataForm.list = data.data.list
                this.dataForm.storeCommission = data.data.storeCommission
                this.dataForm.deliverMoney = data.data.deliverMoney
                this.dataForm.serviceMoney = data.data.serviceMoney
                this.dataForm.platformMoney = data.data.platformMoney
                this.dataForm.payIntegral = data.data.payIntegral
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/business/order/${!this.dataForm.orderid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'orderid': this.dataForm.orderid || undefined,
                'orderno': this.dataForm.orderno,
                'userid': this.dataForm.userid,
                'orderstatus': this.dataForm.orderstatus,
                'totalmoney': this.dataForm.totalmoney,
                'goodscount': this.dataForm.goodscount,
                'delivermoney': this.dataForm.delivermoney,
                'paytype': this.dataForm.paytype,
                'ispay': this.dataForm.ispay,
                'shopid': this.dataForm.shopid,
                'orderremarks': this.dataForm.orderremarks,
                'createtime': this.dataForm.createtime,
                'orderunique': this.dataForm.orderunique,
                'ordersrc': this.dataForm.ordersrc,
                'orderflag': this.dataForm.orderflag,
                'tradeno': this.dataForm.tradeno,
                'payfrom': this.dataForm.payfrom,
                'couponmoney': this.dataForm.couponmoney,
                'confimtime': this.dataForm.confimtime,
                'sucesstime': this.dataForm.sucesstime,
                'buyuserid': this.dataForm.buyuserid,
                'goodsids': this.dataForm.goodsids,
                'storeiphone': this.dataForm.storeiphone,
                'storename': this.dataForm.storename,
                'storeimage': this.dataForm.storeimage,
                'addresstext': this.dataForm.addresstext,
                'marketprice': this.dataForm.marketprice,
                'vipprice': this.dataForm.vipprice,
                'iscommission': this.dataForm.iscommission,
                'commission': this.dataForm.commission,
                'coupons': this.dataForm.coupons,
                'distributiontype': this.dataForm.distributiontype,
                'addressid': this.dataForm.addressid,
                'operationtime': this.dataForm.operationtime,
                'appointmenttime': this.dataForm.appointmenttime,
                'shelvestime': this.dataForm.shelvestime,
                'lngandlat': this.dataForm.lngandlat
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible2 = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
